import { Injectable } from '@angular/core';
import { Resolve, ActivatedRouteSnapshot } from '@angular/router';

import { ListResult } from 'app/modules/base/api-base';
import { ZoneService, Zone } from 'app/modules/zone/services/zone.service';

@Injectable({
  providedIn: 'root',
})
export class ZoneListService implements Resolve<ListResult<Zone>> {
  constructor(private service: ZoneService) {}

  async resolve(route: ActivatedRouteSnapshot) {
    return this.service.list().then(result => {
      result.list = result.list.filter(zone => zone.id);
      return result;
    });
  }
}
